package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.AttendShiftScheduleCycleAddDTO;
import org.jsola.hr.dto.AttendShiftScheduleCycleUpdateDTO;
import org.jsola.hr.entity.AttendShiftScheduleCycleDO;
import org.jsola.hr.query.AttendShiftScheduleCycleQuery;
import org.jsola.hr.service.IAttendShiftScheduleCycleService;
import org.jsola.hr.vo.AttendShiftScheduleCycleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendShiftScheduleCycleTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendShiftScheduleCycleService attendShiftScheduleCycleService;

    /**
     * 生成add测试数据
     * @return AttendShiftScheduleCycleAddDTO
     */
    public AttendShiftScheduleCycleAddDTO getAttendShiftScheduleCycleAddDTO(){
        AttendShiftScheduleCycleAddDTO attendShiftScheduleCycleAddDTO = new AttendShiftScheduleCycleAddDTO();
        attendShiftScheduleCycleAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendShiftScheduleCycleAddDTO.setName(getRandomValue("varchar",50));
        attendShiftScheduleCycleAddDTO.setDaysJson(getRandomValue("varchar",255));
        attendShiftScheduleCycleAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendShiftScheduleCycleAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendShiftScheduleCycleUpdateDTO
     */
    public AttendShiftScheduleCycleUpdateDTO getAttendShiftScheduleCycleUpdateDTO(AttendShiftScheduleCycleVO attendShiftScheduleCycleVO){
        return attendShiftScheduleCycleService.selectDOById(attendShiftScheduleCycleVO.getId(), SITE_ID).to(AttendShiftScheduleCycleUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendShiftScheduleCycleQuery
     */
    public AttendShiftScheduleCycleQuery getAttendShiftScheduleCycleQuery() {
        AttendShiftScheduleCycleQuery attendShiftScheduleCycleQuery = new AttendShiftScheduleCycleQuery();
        List<AttendShiftScheduleCycleDO> attendShiftScheduleCycleDOList = attendShiftScheduleCycleService.list(new AttendShiftScheduleCycleDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendShiftScheduleCycleDOList)) {
            AttendShiftScheduleCycleDO attendShiftScheduleCycleDO = attendShiftScheduleCycleDOList.get(0);
            attendShiftScheduleCycleQuery = attendShiftScheduleCycleDO.to(AttendShiftScheduleCycleQuery.class);
            if (attendShiftScheduleCycleDO.getGmtCreate() != null) {
                attendShiftScheduleCycleQuery.setGmtCreateStart(DateKit.getBeforeDay(attendShiftScheduleCycleDO.getGmtCreate(),-1));
                attendShiftScheduleCycleQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendShiftScheduleCycleDO.getGmtCreate(),1));
            }
            if (attendShiftScheduleCycleDO.getGmtModified() != null) {
                attendShiftScheduleCycleQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendShiftScheduleCycleDO.getGmtModified(),-1));
                attendShiftScheduleCycleQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendShiftScheduleCycleDO.getGmtModified(),1));
            }
        }
        return attendShiftScheduleCycleQuery;
    }

    /**
     * 保存示例
     * @return AttendShiftScheduleCycleVO
     */
    public AttendShiftScheduleCycleVO saveAttendShiftScheduleCycleExample(){
        AttendShiftScheduleCycleAddDTO addDTO = this.getAttendShiftScheduleCycleAddDTO();
        AttendShiftScheduleCycleVO attendShiftScheduleCycleVO = attendShiftScheduleCycleService.save(addDTO,buildTokenUser());
        return attendShiftScheduleCycleVO;
    }


}

